﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Collections;
using FandangoAids;

public class Storage
{
    static string SettingsFile = "config.xml";

    public static List<string[]> Data { get; set; }

    public static string MovieID { get; set; }

    public static string DomainSpins { get; set; }

    public static List<Log.LogOject> Log { get; set; }

    public class StorageInstance
    {
        public List<string[]> Data { get; set; }
        public string MovieID { get; set; }
        public string DomainSpins { get; set; }
        public List<Log.LogOject> Log { get; set; }
    }

    public static void Save()
    {
        var instance = new StorageInstance();
        instance.Data = Data;
        instance.MovieID = MovieID;
        instance.DomainSpins = DomainSpins;
        instance.Log = Log;

        System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(instance.GetType());
        using (var stream = new FileStream(SettingsFile, FileMode.Create))
        {
            x.Serialize(stream, instance);
        }
    }

    public static void Load()
    {
        try
        {
            var instance = new StorageInstance();
            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(instance.GetType());
            using (var stream = new FileStream(SettingsFile, FileMode.OpenOrCreate))
            {
                instance = x.Deserialize(stream) as StorageInstance;
            }

            Data = instance.Data;
            MovieID = instance.MovieID;
            DomainSpins = instance.DomainSpins;
            Log = instance.Log;
        }
        catch
        {
            Data = new List<string[]>();
            MovieID = "";
            DomainSpins = "";
            Log = new List<Log.LogOject>();
        }
    }
}